<template>
    <div class="scheme">
        <el-card shadow="never" class="card-com" >
            <div class="card-1">
                <searchPanel @refresh="getData('reset')" @changePanel="resizeWin">
                    <!-- 查询面板 -->
                    <template v-slot:search>
                        <el-form :inline="true" :model="listSearch" class="demo-form-inline" label-width="120px">
                            <el-row :gutter="20">
                                <el-col :xs="24" :sm="12" :sd="12" :lg="8" :xl="6">
                                    <el-form-item label="方案编码">
                                        <NormalInput v-model:model-value="listSearch.condition.schemeCode"
                                            @get-data="getData('search')"></NormalInput>
                                    </el-form-item>
                                </el-col>
                                <el-col :xs="24" :sm="12" :sd="12" :lg="8" :xl="6">
                                    <el-form-item label="方案类型">
                                        <!-- <NormalInput
                                                v-model:model-value="listSearch.condition.schemeType"
                                                @get-data="getData('search')"></NormalInput> -->
                                        <el-select v-model="listSearch.condition.schemeType" placeholder="请选择方案类型" clearable @change="getData('search')">
                                            <el-option v-for="item in schemeType" :key="item.id" :value="item.id"
                                                :label="item.value"></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                                <el-col :xs="24" :sm="12" :sd="12" :lg="8" :xl="6">
                                    <el-form-item label="方案名称">
                                        <NormalInput v-model:model-value="listSearch.condition.schemeName"
                                            @get-data="getData('search')"></NormalInput>
                                    </el-form-item>
                                </el-col>



                            </el-row>
                            <el-row justify="end">
                                <el-button type="primary" @click="getData('search')">查询</el-button>
                                <el-button @click="getData('reset')">重置</el-button>
                            </el-row>
                        </el-form>
                    </template>
                    <!-- 字段添加 -->
                    <template v-slot:edit>
                        <!-- v-permission="'BLACK_LIST:CREATE-EDIT'" -->
                        <el-button :icon="Plus" type="primary" @click="AddEdit('add')"></el-button>
                        <DropItem v-model:table-prop="tableProp"></DropItem>
                    </template>
                </searchPanel>
            </div>
            <div class="card-2">
                <!-- table数据 -->
                <OnlyTable class="card-2" :tableProps="tableProp" :pageTotal="pageParams.total" @get-page="handPage"
                    :tableData="pageParams.tableData" :tableHeight="pageParams.tableHeight"
                    :loading="pageParams.loadIng">
                    <template #handle="scope">
                        <el-button link type="primary" @click="detailBtn(scope.row)">查看</el-button>
                        <el-button link type="primary" @click="AddEdit('edit', scope.row)">编辑</el-button>
                        <el-button link type="danger" @click="delBtn(scope.row)">删除</el-button>
                    </template>
                </OnlyTable>
            </div>
        </el-card>
        <add :equityList="listCollect.equityList" ref="schemeRef" @refresh="getData('reset')"></add>
        <loop :equityList="listCollect.equityList" ref="loopRef"></loop>
    </div>
</template>

<script setup lang="ts">
import { onMounted, defineAsyncComponent } from "vue";
import { Plus } from "@element-plus/icons-vue"
import { storeToRefs } from "pinia";
import _ from "lodash"
import add from "./component/add.vue"

import { useEnumStore } from "@/store/enumeration";
import { useComListData } from "@/store/list"
import { schemeListStore } from "./pageStore"
const { schemeType } = useEnumStore()
const { schemeRef, loopRef, detailData, tableProp, pageParams, listSearch } = storeToRefs(schemeListStore())
const { AddEdit, getDate1, handPage, delBtn, detailBtn } = schemeListStore()
const loop = defineAsyncComponent(() => import("./component/loop.vue"))
const { listCollect } = useComListData()
onMounted(() => {
    getDate1('reset')

    nextTick(() => {
        const dom1 = document.querySelector(".card-1") as any;
        const dom2 = document.querySelector(".card-com") as any;
        if (dom2) {
            const height = dom2.offsetHeight - dom1.offsetHeight - 70;
            pageParams.value.tableHeight = height;
        }
    })
    window.addEventListener('resize', resizeWin)
})
onUnmounted(() => {
    window.removeEventListener('resize', resizeWin)
})
const resizeWin = _.debounce(() => {
    const dom1 = document.querySelector(".card-1") as any;
    const dom2 = document.querySelector(".card-com") as any;
    if (dom2) {
        const height = dom2.offsetHeight - dom1.offsetHeight - 70;
        pageParams.value.tableHeight = height;
    }
}, 200)

const getData = (type: string) => {
    getDate1(type)

}
</script>

<style scoped lang="scss">
.scheme {
    display: flex;
    height: calc(100vh - 70px);

    .card-com {
        flex-grow: 1;
    }
}
</style>